//
//  LSAttendanceManagementController.m
//  LaSaCivilAffairsDepartment
//
//  Created by 聂志康 on 2019/1/21.
//  Copyright © 2019 wpkj. All rights reserved.
//

#import "LSAttendanceManagementController.h"
#import "LSAttendanceManagementCollectionViewCell.h"
#import "LSAskForLeaveViewController.h"
#import "LSWorkOvertimeApplyViewController.h"
#import "LSCarUsageApplyViewController.h"
#import "LSBusinessTripApplyViewController.h"
#import "LSAttendanceRecordsListViewController.h"
#import "LSWorkOvertimeListViewController.h"
#import "LSWaittingHandleListViewController.h"
#import "LSWorkDayReportViewController.h"

@interface LSAttendanceManagementController () <UICollectionViewDelegate, UICollectionViewDataSource>
@property (nonatomic, strong) UICollectionView *collectionView;
@property (nonatomic, strong) NSArray <NSDictionary *> *contentArray;
@end

static NSString *LSAttendanceManagementCollectionViewCellID = @"LSAttendanceManagementCollectionViewCellID";

@implementation LSAttendanceManagementController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"考勤管理";
    [self.view addSubview:self.collectionView];
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return self.contentArray.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    LSAttendanceManagementCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:LSAttendanceManagementCollectionViewCellID forIndexPath:indexPath];
    cell.mainImageView.image = [UIImage imageNamed:self.contentArray[indexPath.item][@"image"]];
    cell.mainLabel.text = self.contentArray[indexPath.item][@"title"];
    return cell;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    switch (indexPath.item) {
        case 0:
        {
            LSAskForLeaveViewController *askForLeaveVC = [[LSAskForLeaveViewController alloc] init];
            [self.navigationController pushViewController:askForLeaveVC animated:true];
        }
            break;
        case 1:
        {
            LSBusinessTripApplyViewController *businessTripVC = [[LSBusinessTripApplyViewController alloc] init];
            [self.navigationController pushViewController:businessTripVC animated:true];
        }
            break;
        case 2:
        {
            LSCarUsageApplyViewController *carUsageVC = [[LSCarUsageApplyViewController alloc] init];
            [self.navigationController pushViewController:carUsageVC animated:true];
        }
            break;
        case 3:
        {
            LSAttendanceRecordsListViewController *attendanceRecordsListVC = [[LSAttendanceRecordsListViewController alloc] init];
            [self.navigationController pushViewController:attendanceRecordsListVC animated:true];
        }
            break;
        case 4:
        {
            LSWorkOvertimeApplyViewController *workOvertimeVC = [[LSWorkOvertimeApplyViewController alloc] init];
            [self.navigationController pushViewController:workOvertimeVC animated:true];
        }
            break;
        case 5:
        {
            LSWorkOvertimeListViewController *workOvertimeListVC = [[LSWorkOvertimeListViewController alloc] init];
            [self.navigationController pushViewController:workOvertimeListVC animated:true];
        }
            break;
        case 6:
        {
            LSWaittingHandleListViewController *waittingHandleListVC = [[LSWaittingHandleListViewController alloc] init];
            [self.navigationController pushViewController:waittingHandleListVC animated:true];
        }
            break;
        case 7:
        {
            // 工作日志
            LSWorkDayReportViewController *workDayReportVC = [[LSWorkDayReportViewController alloc] init];
            [self.navigationController pushViewController:workDayReportVC animated:true];
        }
            break;
        default:
            break;
    }
}

- (UICollectionView *)collectionView {
    if (!_collectionView) {
        UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
        flowLayout.itemSize = CGSizeMake(ScreenWidth/3, 150);
        flowLayout.scrollDirection = UICollectionViewScrollDirectionVertical;
        flowLayout.minimumLineSpacing = 0;
        flowLayout.minimumInteritemSpacing = 0;
        // 设置左右缩进
        flowLayout.sectionInset = UIEdgeInsetsZero;
        _collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight-SafeAreaTopHeight) collectionViewLayout:flowLayout];
        // 1.设置分页效果
        _collectionView.pagingEnabled = NO;
        // 2.开启弹簧效果
        _collectionView.bounces = YES;
        // 3.关闭底部的滚动条
        _collectionView.showsHorizontalScrollIndicator = NO;
        // 4.开启滑动
        _collectionView.scrollEnabled = true;
        _collectionView.backgroundColor = [UIColor clearColor];
        _collectionView.delegate = self;
        _collectionView.dataSource = self;
        [_collectionView registerClass:[LSAttendanceManagementCollectionViewCell class] forCellWithReuseIdentifier:LSAttendanceManagementCollectionViewCellID];
    }
    return _collectionView;
}

- (NSArray<NSDictionary *> *)contentArray {
    if (!_contentArray) {
        _contentArray = @[@{@"title":@"请假",@"image":@"qj"},
                          @{@"title":@"出差",@"image":@"icon出差"},
                          @{@"title":@"用车",@"image":@"icon用车"},
                          @{@"title":@"考勤列表",@"image":@"icon考勤列表"},
                          @{@"title":@"加班申请",@"image":@"icon加班申请"},
                          @{@"title":@"加班列表",@"image":@"icon加班列表"},
                          @{@"title":@"待办列表",@"image":@"icon待办列表"},
                          @{@"title":@"日志",@"image":@"gzrz"}];
    }
    return _contentArray;
}

@end
